home *** CD-ROM | disk | FTP | other *** search
/ Games of Daze / Infomagic - Games of Daze (Summer 1995) (Disc 1 of 2).iso / x2ftp / msdos / source / demostuf / starwar1.pas < prev    next >
Pascal/Delphi Source File  |  1994-07-25  |  8KB  |  396 lines

  1. program starwars_scroller;
  2. {
  3.     STARWARS SCROLLER
  4.     - by Bjarke Viksφe
  5.     feb 1994
  6.  
  7.     First try. Will be improved...
  8.     Without z-effect!
  9.  
  10.     This is really a big horizontal line-scaler...
  11.  
  12.     The big idea with this scroller is that you precalc each line - that
  13.     is, precalc each xpos which should be used from the colour-map (or the
  14.     actual scroll-area). Eh, for each line you calc the points, ranging
  15.     from 0 to 319, for each pixel on the actual line. The amount of points
  16.     you calc is the size of the line - but you allways calc points from
  17.     0 to 319.
  18.     You can then simply use it as a look-up table to figure out from
  19.     which xpos you should fetch the next colour-pixel.
  20.     (what a shitty explanation...)
  21.  
  22.     Well, in order to speed things up we put precalc'ed data into four
  23.     seperate tables. Each table contains pixels which are 4 pixels apart.
  24.     This way it's much faster to put on a tweaked screen - and we can
  25.     do word-writes to the video-screen (done in the next version)...
  26. }
  27.  
  28. uses
  29.     crt, DEMOINIT, TWEAK1;
  30.  
  31. const
  32.     DEBUG = FALSE;
  33.     LINES = 100;
  34.     ABUFSIZE = 6000;
  35.  
  36.     MAXSTRINGS = 5;
  37.     MAXTEXTSIZE = 80*190;
  38.  
  39.  
  40. type
  41.     addbufptr = ^addbuftype;
  42.     addbuftype = array[0..ABUFSIZE] of word;
  43.     addptrptr = ^addptrtype;
  44.     addptrtype = array[0..lines] of pointer;
  45.     addsizeptr = ^addsizetype;
  46.     addsizetype = array[0..lines] of word;
  47.     xposptr = ^xpostype;
  48.     xpostype = array[0..lines] of word;
  49.  
  50. var
  51.     font : pScreen;
  52.     buffer : pScreen;
  53.     stackseg : word;
  54.  
  55.     addbuffer1 : addbufptr;
  56.     addbuffer2 : addbufptr;
  57.     addbuffer3 : addbufptr;
  58.     addbuffer4 : addbufptr;
  59.     addptrs1 : addptrtype;
  60.     addsize1 : addsizetype;
  61.     xpos1 : xpostype;
  62.     addptrs2 : addptrtype;
  63.     addsize2 : addsizetype;
  64.     xpos2 : xpostype;
  65.     addptrs3 : addptrtype;
  66.     addsize3 : addsizetype;
  67.     xpos3 : xpostype;
  68.     addptrs4 : addptrtype;
  69.     addsize4 : addsizetype;
  70.     xpos4 : xpostype;
  71.  
  72.     scrolloffset : word;
  73.     textpos : integer;
  74.     textypos : integer;
  75.  
  76. const
  77.     display1 : integer = $0000;
  78.     display2 : integer = $4000;
  79.  
  80.     persp : array[0..lines] of word =
  81.     (2,1,1,2,1,1,1,2,1,1,1,2,1,1,1,1,1,1,0,1,1,1,1,0,1,1,1,0,
  82.     1,1,1,0,1,1,0,1,1,0,1,0,1,0,1,0,0,1,0,0,1,0,0,1,0,0,0,1,0,0,0,
  83.     1,0,0,0,1,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
  84.     1,0,0,0,0,0,0,0,0,0,0,0,0);
  85.  
  86.     scrolltext : array[1..MAXSTRINGS] of string[20] =
  87.     ('             ',
  88.      ' DETTE ER EN ',
  89.      '  STARWARS   ',
  90.      ' SCROLLER!!! ',
  91.      '             ');
  92.  
  93.  
  94.  
  95. (*------------------------------------------------*)
  96.  
  97. procedure CalcAddBuffer;
  98. const
  99.     scrsize = 80*200;
  100. var
  101.     x1,x2 : real;
  102.     a1,a2,dela : real;
  103.     x : word;
  104.     i,j : integer;
  105.     index1,size1 : word;
  106.     index2,size2 : word;
  107.     index3,size3 : word;
  108.     index4,size4 : word;
  109. begin
  110.     for i:=0 to ABUFSIZE do addbuffer1^[i]:=0;
  111.     for i:=0 to ABUFSIZE do addbuffer2^[i]:=0;
  112.     for i:=0 to ABUFSIZE do addbuffer3^[i]:=0;
  113.     for i:=0 to ABUFSIZE do addbuffer4^[i]:=0;
  114.  
  115.     index1:=0; index2:=0; index3:=0; index4:=0;
  116.  
  117.     x1:=104.0;
  118.     x2:=215.0;
  119.     for i:=0 to lines do begin
  120.         addptrs1[i]:=@addbuffer1^[index1];
  121.         addptrs2[i]:=@addbuffer2^[index2];
  122.         addptrs3[i]:=@addbuffer3^[index3];
  123.         addptrs4[i]:=@addbuffer4^[index4];
  124.         size1:=0; size2:=0; size3:=0; size4:=0;
  125.  
  126.         a1:=0.0; a2:=319.0;
  127.         dela := 319.0/(x2-x1);
  128.  
  129.         for j:=round(x1) to round(x2) do begin
  130.             x:=round(a1);
  131.             case (j and 3) of
  132.                 0 : begin
  133.                     if (size1=0) then xpos1[i]:=j shr 2;
  134.                     addbuffer1^[index1]:=(x shr 2)+((x and 3)*scrsize);
  135.                     inc(index1); inc(size1);
  136.                      end;
  137.                 1 : begin
  138.                     if (size2=0) then xpos2[i]:=j shr 2;
  139.                     addbuffer2^[index2]:=(x shr 2)+((x and 3)*scrsize);
  140.                     inc(index2); inc(size2);
  141.                      end;
  142.                 2 : begin
  143.                     if (size3=0) then xpos3[i]:=j shr 2;
  144.                     addbuffer3^[index3]:=(x shr 2)+((x and 3)*scrsize);
  145.                     inc(index3); inc(size3);
  146.                      end;
  147.                 3 : begin
  148.                     if (size4=0) then xpos4[i]:=j shr 2;
  149.                     addbuffer4^[index4]:=(x shr 2)+((x and 3)*scrsize);
  150.                     inc(index4); inc(size4);
  151.                      end;
  152.             end;
  153.             a1:=a1+dela;
  154.         end;
  155.         addsize1[i]:=size1;
  156.         addsize2[i]:=size2;
  157.         addsize3[i]:=size3;
  158.         addsize4[i]:=size4;
  159.         x1:=x1-1.0;
  160.         x2:=x2+1.0;
  161.     end;
  162. end;
  163.  
  164. procedure SetScrollText;
  165. var
  166.     i,j : integer;
  167. begin
  168.     for i:=1 to MAXSTRINGS do
  169.         for j:=1 to length(scrolltext[i]) do
  170.             case scrolltext[i,j] of
  171.             ' ' : scrolltext[i,j]:=char(ord('A')+48);
  172.             '!' : scrolltext[i,j]:=char(ord('Z')+11);
  173.             '.' : scrolltext[i,j]:=char(ord('Z')+12);
  174.             '?' : scrolltext[i,j]:=char(ord('Z')+13);
  175.             end;
  176. end;
  177.  
  178. procedure SetupDemo;
  179. var
  180.     i : word;
  181. begin
  182.     ClearWholeScreen;
  183.     CalcAddBuffer;
  184.     SetScrollText;
  185.  
  186.     for i:=0 to 65000 do buffer^[i]:=0;
  187.     for i:=0 to lines do persp[i]:=persp[i]*WIDTH;
  188.     scrolloffset:=0;
  189.     textpos:=1; textypos:=0;
  190. end;
  191.  
  192.  
  193. (*------------------------------------------------*)
  194.  
  195. procedure SwapDisplay;
  196. var
  197.     temp : word;
  198. begin
  199.     temp:=display1;
  200.     display1:=display2;
  201.     display2:=temp;
  202.     SetAddress(Ptr(SEGA000,display2));
  203. end;
  204.  
  205.  
  206. (*------------------------------------------------*)
  207.  
  208. procedure StarWars(addptrs : addptrptr; addsize : addsizeptr; xpos : xposptr);
  209. var
  210.     i : integer;
  211.     scrx, scry : word;
  212.     scrollpos : word;
  213.     bptr : pointer;
  214.     size : word;
  215. begin
  216.     scry := WIDTH*90;
  217.     scrollpos:=scrolloffset;
  218.  
  219.     for i:=0 to lines do begin
  220.     bptr := addptrs^[i];
  221.     scrx := xpos^[i];
  222.     size := addsize^[i];
  223.     scrollpos:=scrollpos+persp[i];
  224.     if (scrollpos >= MAXTEXTSIZE) then dec(scrollpos,MAXTEXTSIZE);
  225.     asm
  226.         mov    stackseg,ss
  227.         mov    es,SEGA000
  228.         mov    di,display1
  229.         add    di,scry
  230.         add    di,scrx
  231.         mov    ax,WORD PTR buffer+2
  232.         mov    dx,WORD PTR buffer
  233.         add    dx,scrollpos
  234.         mov    cx,size
  235.         lds    si,bptr
  236.         mov    ss,ax
  237.         cld
  238. @xloop:
  239.         lodsw
  240.         mov    bx,ax
  241.         add    bx,dx
  242.         mov    al,ss:[bx]
  243.         stosb
  244.         loop    @xloop
  245.         mov    ax,SEG @DATA
  246.         mov    ds,ax
  247.         mov    ss,stackseg
  248.     end;
  249.     inc(scry,WIDTH);
  250.     inc(scrollpos,WIDTH);
  251.     if (scrollpos = MAXTEXTSIZE) then scrollpos:=0;
  252.     end;
  253. end;
  254.  
  255. procedure Scroller;
  256. var
  257.     i : integer;
  258.     plotoffset : word;
  259.     yoff,stroff : word;
  260.     textantal : integer;
  261. begin
  262.     inc(scrolloffset,WIDTH);
  263.     if (scrolloffset = MAXTEXTSIZE) then scrolloffset:=0;
  264.     plotoffset:=scrolloffset+(180*WIDTH);
  265.     if (plotoffset >= MAXTEXTSIZE) then dec(plotoffset,MAXTEXTSIZE);
  266.  
  267.     inc(textypos);
  268.     if (textypos = 31) then begin
  269.         textypos:=0;
  270.         inc(textpos); if (textpos > MAXSTRINGS) then textpos:=1;
  271.     end;
  272.     yoff := textypos*WIDTH;
  273.     stroff := (textpos-1)*21;
  274.  
  275.     asm
  276.         mov    textantal,1
  277. @loop:
  278.         lea    si,scrolltext
  279.         add    si,stroff
  280.         add    si,textantal
  281.         mov    al,[si]
  282.         xor    ah,ah
  283.  
  284.         cmp    al,' '
  285.         jne    @char1
  286.         mov    al,'A'+48
  287. @char1:
  288.         cmp    al,'!'
  289.         jne    @char2
  290.         mov    al,'Z'+11
  291. @char2:
  292.         cmp    al,'.'
  293.         jne    @char3
  294.         mov    al,'Z'+12
  295. @char3:
  296.         cmp    al,'A'
  297.         jb        @noprint
  298.         sub    al,'A'
  299.         xor    dx,dx
  300.         mov    cx,10
  301.         div    cx
  302.         mov    bx,dx
  303.         mov    cx,80*32
  304.         xor    dx,dx
  305.         mul    cx
  306.         shl    bx,3
  307.  
  308.         push    ds
  309.         les    di,buffer
  310.         lds    si,font
  311.         add    si,yoff
  312.         add    si,ax
  313.         add    si,bx
  314.         add    di,plotoffset
  315.         cld
  316.         mov    bx,(80*200)-6
  317.         movsw
  318.         movsw
  319.         movsw
  320.         add    si,bx
  321.         add    di,bx
  322.         movsw
  323.         movsw
  324.         movsw
  325.         add    si,bx
  326.         add    di,bx
  327.         movsw
  328.         movsw
  329.         movsw
  330.         add    si,bx
  331.         add    di,bx
  332.         movsw
  333.         movsw
  334.         movsw
  335.         pop    ds
  336.  
  337. @noprint:
  338.         add    plotoffset,6
  339.         inc    textantal
  340.         cmp    textantal,15
  341.         jne    @loop
  342.     end;
  343. end;
  344.  
  345.  
  346. (*------------------------------------------------*)
  347.  
  348. procedure RunOnce;
  349. begin
  350.     SwapDisplay;
  351.     VBLANK;
  352.     if DEBUG then setRGB(0,63,0,0);
  353.     SetBitplanes(1);
  354.     StarWars(@addptrs1,@addsize1,@xpos1);
  355.     SetBitplanes(2);
  356.     StarWars(@addptrs2,@addsize2,@xpos2);
  357.     SetBitplanes(4);
  358.     StarWars(@addptrs3,@addsize3,@xpos3);
  359.     SetBitplanes(8);
  360.     StarWars(@addptrs4,@addsize4,@xpos4);
  361.     Scroller;
  362.     if DEBUG then setRGB(0,0,0,0);
  363. end;
  364.  
  365. var
  366.     i,j : integer;
  367.  
  368. begin
  369.     new(font);
  370.     new(buffer);
  371.     new(addbuffer1);
  372.     new(addbuffer2);
  373.     new(addbuffer3);
  374.     new(addbuffer4);
  375.     LoadPix(font,'FONT.LBM');
  376.     OpenScreen;
  377.     SetCMAP;
  378.     SetupDemo;
  379.  
  380.     while (not KeyPressed) do
  381.     begin
  382.         RunOnce;
  383.     end;
  384.  
  385.     CloseScreen;
  386.     dispose(addbuffer1);
  387.     dispose(addbuffer2);
  388.     dispose(addbuffer3);
  389.     dispose(addbuffer4);
  390.     dispose(buffer);
  391.     dispose(font);
  392.  
  393.     crt.textmode(co80);
  394.     writeln('ok..');
  395. end.
  396. -